import React from 'react';
import {Button, Icon} from 'antd';
import {WeaTools, WeaDialog, WeaTable} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import SynergySetting4Designer from './SynergySetting4Designer';

class SynergySetting4WfVersions extends React.Component {
    state = {visible: false, loading: false, data: [], settingParams: {}};

    constructor(props) {
        super(props);
        this.getButtons = this.getButtons.bind(this);
        this.onOk = this.onOk.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }

    render() {
        const {visible, loading, data, settingParams} = this.state;

        const columns = [{
            key: 'workflowname',
            title: '流程名称',
            dataIndex: 'workflowname',
            width: '70%'
        }, {
            key: 'operation',
            title: getLabel(30585,'操作'),
            width: '30%',
            render: (text, record) => (
                <span className="synergy-setting-btn" onClick={() => this.ss4d.onShow({...settingParams, wfid: record.id})}>{getLabel(17632	,'参数设置')}</span>
            )
        }];

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@a2x9st`}
                visible={visible}
                loading={loading}
                title="流程参数设置"
                icon="icon-coms-synergism"
                iconBgcolor='#1a57a0'
                style={{width: 500, height: 240}}
                hasScroll={true}
                buttons={this.getButtons()}
                onCancel={this.onCancel}
            >
                <SynergySetting4Designer ecId={`${this && this.props && this.props.ecId || ''}_SynergySetting4Designer@aourvv`} ref={(ss4d) => this.ss4d = ss4d}/>
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@k8q1a9`} columns={columns} dataSource={data} pagination={false}/>
            </WeaDialog>
        );
    }

    onShow(params) {
        this.setState({visible: true, loading: true, settingParams: params});

        const {eid, tabid} = params;
        WeaTools.callApi('/api/portal/synergy/getWfVersions', 'GET', {eid, tabid}).then(data => {
            this.setState({loading: false, data: data.data || []});
        });
    }

    getButtons() {
        let buttons = [];
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bha3p7`} type="primary" onClick={this.onOk}>{getLabel(826, '确定')}</Button>);
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@022ia1`} type="ghost" onClick={this.onCancel}>{getLabel(309, '关闭')}</Button>);
        return buttons;
    }

    onOk() {
        this.onCancel();
    }

    onCancel() {
        this.setState({visible: false, data: []});
    }
}

export default SynergySetting4WfVersions;
